﻿// -------------------------------------------------------------------------
//    @FileName         :    GameApi.h
//    @Author           :    gaoyi
//    @Date             :    24-8-1
//    @Email            :    445267987@qq.com
//    @Module           :    GameApi
//
// -------------------------------------------------------------------------

#pragma once

#include "NFComm/NFCore/NFPlatform.h"
#include <iostream>
#include <NFComm/NFPluginModule/NFIDynamicModule.h>
#include <NFComm/NFShmStl/NFShmString.h>
#include <NFComm/NFShmStl/NFShmVector.h>

#include "proto_cs.pb.h"
#include "IAction.h"
#include "NFLogicCommon/NFSecurity.h"
#include "NFComm/NFShmStl/NFShmString.h"

using namespace std;

enum EGameState
{
	EN_STATE_NONE        = 0,
	EN_STATE_CONNECTTING = 1,
	EN_STATE_CONNECTED   = 2,
	EN_STATE_LOGIN       = 3,
	EN_STATE_CREATE_ROLE = 4,
	EN_STATE_GET_ROLE    = 5,
	EN_STATE_ONLINE      = 6,
};

const int MAX_OPEN_ID_LEN         = 32;
const int MAX_PACKET_LEN          = 65535;
const int MAX_SEND_PACKET_LEN     = 1024;
const int MAX_ROLE_NUM_PRE_PLAYER = 7;

class GameApi : public NFIDynamicModule, public NFSecurity
{
public:
	GameApi(NFIPluginManager* p);

	virtual ~GameApi();
public:
	int Init(int uid);
	int Login(int uid, int iActorID, const std::string& pszIp, int iPort);
	int LoginSvr(const std::string& pszIp, int iPort);
public:
	int HandleCSPacket(int iCmd, proto_ff::Proto_CSRsp& oCSRsp);
public:
	int ConnectSvr(const std::string& pszIp, int iPort);
	int ConnectSuccess();
	int DisconnectSvr();
	int OnProxySocketEvent(eMsgType nEvent, uint64_t unLinkId);
	int OnHandleProxyAllMessage(uint64_t unLinkId, NFDataPackage& packet);
public:
	int Send(proto_client2access::Proto_C2ACmd iCmd, const google::protobuf::Message& xData, uint32_t seq);
	int Send(proto_client2access::Proto_C2ACmd iCmd, const std::string& msgData, uint32_t seq);
	int Send(uint32_t nMsgId, proto_ff::Proto_CSReq& xData, uint32_t seq);
	int Recv(char* pszBuff, int iMaxLen);
public:
	int GetSendSeq()
	{
		m_iSendSeq++;
		return m_iSendSeq;
	}

	int GetUid() { return m_iUid; }

	char* GetOpenID() { return m_szOpenID; }
public:
	int  m_iUid;
	char m_szOpenID[MAX_OPEN_ID_LEN];

	int m_iActorID;
	int m_iProf;

	NFShmVector<uint64_t, MAX_ROLE_NUM_PRE_PLAYER> m_allRoleID;

	uint64_t m_ullLoginRoleID;
	int      m_iLastHeartBeatTime;

	proto_client2access::Proto_C2AEncryptType  m_encrypt_type;
	proto_client2access::Proto_C2ACompressType m_compress_type;

	//gamesvr connect
	int        m_iSocketFd;
	EGameState m_eState;
	int        m_iSendSeq;
	NFBuffer   m_szRecvBuf;
	int        m_iRecvSize;
	NFBuffer   m_szSendBuffer;

	//guild
	uint64_t m_ullGuildId;
	uint32_t m_iGuildListPageIdx;
	uint64_t m_ullApplyGuildId;
};
